1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module soup.HSTSEnforcer;
26 
27 private import glib.ConstructionException;
28 private import glib.ListG;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import soup.HSTSPolicy;
33 private import soup.Message;
34 private import soup.SessionFeatureIF;
35 private import soup.SessionFeatureT;
36 private import soup.c.functions;
37 public  import soup.c.types;
38 private import std.algorithm;
39 
40 
41 /** */
42 public class HSTSEnforcer : ObjectG, SessionFeatureIF
43 {
44 	/** the main Gtk struct */
45 	protected SoupHSTSEnforcer* soupHSTSEnforcer;
46 
47 	/** Get the main Gtk struct */
48 	public SoupHSTSEnforcer* getHSTSEnforcerStruct(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return soupHSTSEnforcer;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)soupHSTSEnforcer;
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (SoupHSTSEnforcer* soupHSTSEnforcer, bool ownedRef = false)
65 	{
66 		this.soupHSTSEnforcer = soupHSTSEnforcer;
67 		super(cast(GObject*)soupHSTSEnforcer, ownedRef);
68 	}
69 
70 	// add the SessionFeature capabilities
71 	mixin SessionFeatureT!(SoupHSTSEnforcer);
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return soup_hsts_enforcer_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new #SoupHSTSEnforcer. The base #SoupHSTSEnforcer class
82 	 * does not support persistent storage of HSTS policies, see
83 	 * #SoupHSTSEnforcerDB for that.
84 	 *
85 	 * Returns: a new #SoupHSTSEnforcer
86 	 *
87 	 * Since: 2.68
88 	 *
89 	 * Throws: ConstructionException GTK+ fails to create the object.
90 	 */
91 	public this()
92 	{
93 		auto __p = soup_hsts_enforcer_new();
94 
95 		if(__p is null)
96 		{
97 			throw new ConstructionException("null returned by new");
98 		}
99 
100 		this(cast(SoupHSTSEnforcer*) __p, true);
101 	}
102 
103 	/**
104 	 * Gets a list of domains for which there are policies in @enforcer.
105 	 *
106 	 * Params:
107 	 *     sessionPolicies = whether to include session policies
108 	 *
109 	 * Returns: a newly allocated
110 	 *     list of domains. Use g_list_free_full() and g_free() to free the
111 	 *     list.
112 	 *
113 	 * Since: 2.68
114 	 */
115 	public ListG getDomains(bool sessionPolicies)
116 	{
117 		auto __p = soup_hsts_enforcer_get_domains(soupHSTSEnforcer, sessionPolicies);
118 
119 		if(__p is null)
120 		{
121 			return null;
122 		}
123 
124 		return new ListG(cast(GList*) __p, true);
125 	}
126 
127 	/**
128 	 * Gets a list with the policies in @enforcer.
129 	 *
130 	 * Params:
131 	 *     sessionPolicies = whether to include session policies
132 	 *
133 	 * Returns: a newly
134 	 *     allocated list of policies. Use g_list_free_full() and
135 	 *     soup_hsts_policy_free() to free the list.
136 	 *
137 	 * Since: 2.68
138 	 */
139 	public ListG getPolicies(bool sessionPolicies)
140 	{
141 		auto __p = soup_hsts_enforcer_get_policies(soupHSTSEnforcer, sessionPolicies);
142 
143 		if(__p is null)
144 		{
145 			return null;
146 		}
147 
148 		return new ListG(cast(GList*) __p, true);
149 	}
150 
151 	/**
152 	 * Gets whether @hsts_enforcer has a currently valid policy for @domain.
153 	 *
154 	 * Params:
155 	 *     domain = a domain.
156 	 *
157 	 * Returns: %TRUE if access to @domain should happen over HTTPS, false
158 	 *     otherwise.
159 	 *
160 	 * Since: 2.68
161 	 */
162 	public bool hasValidPolicy(string domain)
163 	{
164 		return soup_hsts_enforcer_has_valid_policy(soupHSTSEnforcer, Str.toStringz(domain)) != 0;
165 	}
166 
167 	/**
168 	 * Gets whether @hsts_enforcer stores policies persistenly.
169 	 *
170 	 * Returns: %TRUE if @hsts_enforcer storage is persistent or %FALSE otherwise.
171 	 *
172 	 * Since: 2.68
173 	 */
174 	public bool isPersistent()
175 	{
176 		return soup_hsts_enforcer_is_persistent(soupHSTSEnforcer) != 0;
177 	}
178 
179 	/**
180 	 * Sets @policy to @hsts_enforcer. If @policy is expired, any
181 	 * existing HSTS policy for its host will be removed instead. If a
182 	 * policy existed for this host, it will be replaced. Otherwise, the
183 	 * new policy will be inserted. If the policy is a session policy, that
184 	 * is, one created with soup_hsts_policy_new_session_policy(), the policy
185 	 * will not expire and will be enforced during the lifetime of
186 	 * @hsts_enforcer's #SoupSession.
187 	 *
188 	 * Params:
189 	 *     policy = the policy of the HSTS host
190 	 *
191 	 * Since: 2.68
192 	 */
193 	public void setPolicy(HSTSPolicy policy)
194 	{
195 		soup_hsts_enforcer_set_policy(soupHSTSEnforcer, (policy is null) ? null : policy.getHSTSPolicyStruct());
196 	}
197 
198 	/**
199 	 * Sets a session policy for @domain. A session policy is a policy
200 	 * that is permanent to the lifetime of @hsts_enforcer's #SoupSession
201 	 * and doesn't expire.
202 	 *
203 	 * Params:
204 	 *     domain = policy domain or hostname
205 	 *     includeSubdomains = %TRUE if the policy applies on sub domains
206 	 *
207 	 * Since: 2.68
208 	 */
209 	public void setSessionPolicy(string domain, bool includeSubdomains)
210 	{
211 		soup_hsts_enforcer_set_session_policy(soupHSTSEnforcer, Str.toStringz(domain), includeSubdomains);
212 	}
213 
214 	/**
215 	 * Emitted when @hsts_enforcer changes. If a policy has been added,
216 	 * @new_policy will contain the newly-added policy and
217 	 * @old_policy will be %NULL. If a policy has been deleted,
218 	 * @old_policy will contain the to-be-deleted policy and
219 	 * @new_policy will be %NULL. If a policy has been changed,
220 	 * @old_policy will contain its old value, and @new_policy its
221 	 * new value.
222 	 *
223 	 * Note that you shouldn't modify the policies from a callback to
224 	 * this signal.
225 	 *
226 	 * Params:
227 	 *     oldPolicy = the old #SoupHSTSPolicy value
228 	 *     newPolicy = the new #SoupHSTSPolicy value
229 	 */
230 	gulong addOnChanged(void delegate(HSTSPolicy, HSTSPolicy, HSTSEnforcer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
231 	{
232 		return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
233 	}
234 
235 	/**
236 	 * Emitted when @hsts_enforcer has upgraded the protocol
237 	 * for @message to HTTPS as a result of matching its domain with
238 	 * a HSTS policy.
239 	 *
240 	 * Params:
241 	 *     message = the message for which HSTS is being enforced
242 	 */
243 	gulong addOnHstsEnforced(void delegate(Message, HSTSEnforcer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
244 	{
245 		return Signals.connect(this, "hsts-enforced", dlg, connectFlags ^ ConnectFlags.SWAPPED);
246 	}
247 }